/*  Written by FanLin  Reference to simple.flex & lcalc.flex*/
/*  Still need to be added some to specify COMMENT */ 

/* Usercode Section */
import java_cup.runtime.*;

%%

/* Option and Declarations Section*/
%class miniJava
%line
%column
%cup
%{ 
  /*  private int comment_count = 0;  (it can be used when COMMENT can be used >_<)   */
     
     
    private Symbol symbol(int type) {
        return new Symbol(type, yyline, yycolumn);
    }
    
    private Symbol symbol(int type, Object value) {
        return new Symbol(type, yyline, yycolumn, value);
    }
%}


DIGIT=[0-9]
/*SYMBOL =+|-*/
INTEGER=0|[1-9][0-9]*
ALPHA=[A-Za-z]
LINETERMINAL=\r|\n|\r\n
WHITESPACE={LINETERMINAL}|[ \t\f]
IDENTIFIER={ALPHA}({ALPHA}|{DIGIT}|_)*

%%

/* Lexical Rules Section */

<YYINITIAL>{
  "class"    { return symbol(sym.CLASS); }
  "public"   { return symbol(sym.PUBLIC); }
  "static"   { return symbol(sym.STATIC); }
  "void"     { return symbol(sym.VOID); }
  "main"     { return symbol(sym.MAIN); }
  "String"   { return symbol(sym.STRING); }
  "extends"  { return symbol(sym.EXTENDS); }
  "return"   { return symbol(sym.RETURN); }
  "int"      { return symbol(sym.INT); }
  "boolean"  { return symbol(sym.BOOLEAN); }
  "if"       { return symbol(sym.IF); }
  "while"    { return symbol(sym.WHILE); }
  "true"     { return symbol(sym.TRUE); }
  "false"    { return symbol(sym.FALSE); }
  "this"     { return symbol(sym.THIS); }
  "new"      { return symbol(sym.NEW); }
  "else"		 { return symbol(sym.ELSE); }
  /* only appear in the MiniJava  from here to next comment*/
  
  "System" { return symbol(sym.SYSTEM); }
  "out" { return symbol(sym.OUT); }
  "println" { return symbol(sym.PRINTLN); }
  "length" { return symbol(sym.LENGTH); }
  /* stop here */
  /*"\"" { return symbol(sym.QUOTO)}*/
  ","  { return symbol(sym.COMMA); }
  ";"  { return symbol(sym.SEMI); }
  "("  { return symbol(sym.LSPAREN); }
  ")"  { return symbol(sym.RSPAREN); }
  "["  { return symbol(sym.LMPAREN); }
  "]"  { return symbol(sym.RMPAREN); }
  "{"  { return symbol(sym.LBPAREN); }
  "}"  { return symbol(sym.RBPAREN); }
  "."  { return symbol(sym.POINT); }
  "+"  { return symbol(sym.ADD); }
  "-"  { return symbol(sym.MINUS); }
  "*"  { return symbol(sym.TIMES); }
  "="  { return symbol(sym.EQUAL); }
  "&&" { return symbol(sym.AND); }
  "<"  { return symbol(sym.LESS); }
  "!"  { return symbol(sym.DENY); }
 
  {INTEGER} { return symbol(sym.INTEGER, new Integer(yytext())); }
  
  {IDENTIFIER} { return symbol(sym.ID, new String(yytext())); }
  
  {WHITESPACE}+  {}
}
[^]  { throw new Error ("Illegal character <"+yytext()+">"); }
